home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / gfa / srgexmpl.lzh / SRGEXMPL.LST next >
Encoding:
File List  |  1993-07-25  |  11.4 KB  |  322 lines

  1. $m29952  ! Get some memory for our application.
  2. '
  3. '  SRG Window Resource Example
  4. '  by Scott R. Garrigus
  5. '  SRG Software  July 25, 1993
  6. '
  7. '  This code can be freely distributed as long it is done intact.  It can
  8. '  be used freely in whole or in part in your own programs.  FREEWARE from
  9. '  SRG Software.
  10. '
  11. '  This application runs both as an ACC and as a PRG.
  12. '  It is an example showing how to use a resource dialog in a window.
  13. '
  14. ap_id&=APPL_INIT()  ! Get an ID number for our ACC/PRG from AES.
  15. '
  16. IF ap_id&<>0   ! If we're run as an ACC...
  17.   '
  18.   IF RSRC_LOAD("srgexmpl.rsc")=0  ! If resource can't be found...
  19.     '
  20.     resource!=FALSE  !  Set resource flag to false.
  21.     '
  22.     DIM message_buffer&(7)  ! Set up a buffer for AES messages.
  23.     mesg_adr%=V:message_buffer&(0)  !  Get the address of the buffer.
  24.     '
  25.     '  Set up the variables needed when receiving messages.
  26.     '
  27.     ABSOLUTE mesg_type&,mesg_adr%  ! Holds the type of message received.
  28.     ABSOLUTE x&,mesg_adr%+8  ! x coordinate of redraw area or window.
  29.     ABSOLUTE y&,mesg_adr%+10  ! y coordinate of redraw area or window.
  30.     ABSOLUTE w&,mesg_adr%+12  ! width of redraw area or window.
  31.     ABSOLUTE h&,mesg_adr%+14  ! height of redraw area or window.
  32.     ABSOLUTE acc_id&,mesg_adr%+8  ! Holds the ID of the ACC activated by user.
  33.     '
  34.     ' Put our ACC name in the Desk menu and save the number of the
  35.     ' menu slot it is in.
  36.     '
  37.     me_id&=MENU_REGISTER(ap_id&,"  SRG RSC Example ")
  38.     '
  39.   ELSE  ! If our resource was found...
  40.     resource!=TRUE  ! Set our resource flag to true.
  41.     exit!=TRUE  ! Set our exit flag to true, because we are just
  42.     '                 initializing right now.  The ACC is not open yet.
  43.     '
  44.     @init  ! Do the rest of our initialization.  Both ACC and PRG.
  45.     '
  46.     ' The following variables are only needed by the ACC.
  47.     '
  48.     ' Put our ACC name in the Desk menu and save the number of the
  49.     ' menu slot it is in.
  50.     '
  51.     me_id&=MENU_REGISTER(ap_id&,"  SRG RSC Example ")
  52.     '
  53.   ENDIF
  54.   '
  55.   ' Now enter the main ACC loop and loop forever, since ACC's
  56.   ' are never exited.
  57.   '
  58.   DO
  59.     @do_events  !Get event messages from AES.
  60.   LOOP
  61.   '
  62. ELSE  ! If we're run as a PRG...
  63.   '
  64.   IF RSRC_LOAD("srgexmpl.rsc")=0  ! If our resource can't be found...
  65.     '
  66.     ~FORM_ALERT(1,"[1][Resource not found.][Bye]")  ! Alert the user,
  67.     '
  68.     ~APPL_EXIT()  ! and exit the program.
  69.     QUIT (0)
  70.     '
  71.   ELSE  ! If our resource was found...
  72.     '
  73.     resource!=TRUE  ! Set our resource flag to true.
  74.     '
  75.   ENDIF
  76.   '
  77.   @init  ! Do the rest of our initialization.  Both ACC and PRG.
  78.   '
  79.   ' The following variables are those needed for the PRG only.
  80.   '
  81.   ' Set up variables for our menu bar, which was created with the RCS.
  82.   '
  83.   LET menu&=2  ! Menu object number.
  84.   LET deskmenu&=6  ! Desk object numer.
  85.   '
  86.   ' Set up variables to hold the menu title and menu item numbers
  87.   ' which are selected by the user when an AES menu message occurs.
  88.   '
  89.   ABSOLUTE m_title&,mesg_adr%+6  ! Holds the menu title object number.
  90.   ABSOLUTE m_item&,mesg_adr%+8  ! Holds the menu item object number.
  91.   '
  92.   ~RSRC_GADDR(0,menu&,menu_adr%)  ! Get the address of our menu, which
  93.   '                                 was loaded in with the RCS file.
  94.   '
  95.   ~MENU_BAR(menu_adr%,1)  ! Display our menu bar on the screen.
  96.   '
  97.   @do_window  ! Set up and open our window.
  98.   '
  99.   exit!=FALSE  ! Set our exit flag to false since we are not exiting yet.
  100.   '
  101.   ~GRAF_MOUSE(0,pattern_adr%)  ! Set the mouse to an arrow.
  102.   '
  103.   ' Now loop until our exit flag is true.
  104.   '
  105.   REPEAT
  106.     @do_events  ! Get event messages from AES.
  107.   UNTIL exit!
  108.   '
  109. ENDIF
  110. '
  111. ~MENU_BAR(menu_adr%,0)  ! Turn our menu bar off.
  112. '
  113. ~RSRC_FREE()  ! Free up the memory our resource file took.
  114. '
  115. ~APPL_EXIT()  ! Exit our program.
  116. QUIT (0)
  117. '
  118. '
  119. '
  120. PROCEDURE init
  121.   '
  122.   ' This is where we initialize things pertaining to both the ACC and
  123.   ' the PRG.
  124.   '
  125.   ' Variables from our resource file.
  126.   '
  127.   LET maindial&=0 ! Main dialog tree.
  128.   LET infobutn&=1 ! Info button in main dialog.
  129.   '
  130.   LET crdtdial&=1 ! Credit dialog tree.
  131.   LET crdtbutn&=9 ! Credit button in credit dialog.
  132.   '
  133.   DIM message_buffer&(7)  ! Set up a buffer for AES messages.
  134.   mesg_adr%=V:message_buffer&(0)  ! Get the address of the buffer.
  135.   '
  136.   ' Set up the varibles needed when receiving messages.
  137.   '
  138.   ABSOLUTE mesg_type&,mesg_adr%  ! Holds the type of message received.
  139.   ABSOLUTE x&,mesg_adr%+8  ! x coordinate of redraw area or window.
  140.   ABSOLUTE y&,mesg_adr%+10  ! y coordinate of redraw area or window.
  141.   ABSOLUTE w&,mesg_adr%+12  ! width of redraw area or window.
  142.   ABSOLUTE h&,mesg_adr%+14  ! height of redraw area or window.
  143.   ABSOLUTE acc_id&,mesg_adr%+8  ! Holds the ID of the ACC activated by user.
  144.   ABSOLUTE window_selected&,mesg_adr%+6  ! Holds the handle of the window
  145.   '                                        that was selected by the user.
  146.   '
  147.   ' Get the addresses of all the dialogs used in the ACC/PRG.
  148.   '
  149.   ~RSRC_GADDR(0,maindial&,maindial_adr%)
  150.   ~RSRC_GADDR(0,crdtdial&,crdtdial_adr%)
  151.   '
  152.   ' Get the starting coordinates (center of screen) of the dialogs.
  153.   '
  154.   ~FORM_CENTER(maindial_adr%,mainx&,mainy&,mainw&,mainh&)
  155.   ~FORM_CENTER(crdtdial_adr%,crdtx&,crdty&,crdtw&,crdth&)
  156.   '
  157.   ' Compute the total size we need our window to be by using
  158.   ' the size of the MIDI dialog, which will fit inside the
  159.   ' window work area.  Our window will have a title bar with
  160.   ' name, a close box, and a movement bar. (eg. 1+2+8)
  161.   '
  162.   ~WIND_CALC(0,1+2+8,mainx&,mainy&,mainw&,mainh&,windx&,windy&,windw&,windh&)
  163.   '
  164. RETURN
  165. '
  166. '
  167. PROCEDURE do_window
  168.   '
  169.   ' Create our main window to the appropriate size as to fit our
  170.   ' resource menu inside the work area.
  171.   '
  172.   handle&=WIND_CREATE(1+2+8,windx&,windy&,windw&,windh&)
  173.   '
  174.   ' Set up a title for our window
  175.   '
  176.   title$=" SRG RSC Window Example "  ! Be sure title has even # of chars.
  177.   adr_title%=V:title$  ! Get the address of the title.
  178.   '
  179.   ' Assign the title to our window
  180.   '
  181.   ~WIND_SET(handle&,2,CARD(SWAP(adr_title%)),CARD(adr_title%),0,0)
  182.   '
  183.   ' Open our window and find the coordinates of it's work area.
  184.   '
  185.   ~WIND_OPEN(handle&,windx&,windy&,windw&,windh&)
  186.   ~WIND_GET(handle&,4,wx&,wy&,ww&,wh&)
  187.   '
  188.   ' Set the coordinates of our resource menu to that of the
  189.   ' window work area and then a redraw will display it inside the window.
  190.   OB_X(maindial_adr%,0)=wx&
  191.   OB_Y(maindial_adr%,0)=wy&
  192.   '
  193. RETURN
  194. '
  195. '
  196. PROCEDURE do_events
  197.   '
  198.   ' Get both message and left mouse button events.
  199.   '
  200.   evnt%=EVNT_MULTI(2+16,1,1,1,0,0,0,0,0,0,0,0,0,0,mesg_adr%,0,mcur_x%,mcur_y%,button%,dummy%,dummy%,dummy%)
  201.   IF resource! AND exit!=FALSE  ! If resource found and not exited...
  202.     IF BTST(evnt%,1)  ! If it's a button event...
  203.       @process_maindial  ! Find out what was pressed and process it.
  204.     ENDIF
  205.   ENDIF
  206.   IF BTST(evnt%,4)  ! If it's a message event...
  207.     @process_message  ! Find out what type of message and process it.
  208.   ENDIF
  209. RETURN
  210. '
  211. '
  212. PROCEDURE process_message
  213.   '
  214.   SELECT mesg_type&  ! Get the type of message received.
  215.     '
  216.   CASE 10   ! If it's a menu message...
  217.     IF ap_id&=0  ! and if we're run as a PRG...
  218.       IF m_item&=deskmenu&  ! If the desk menu is selected...
  219.         @do_credits  ! display our credits dialog.
  220.         ~MENU_TNORMAL(menu_adr%,m_title&,1)  ! Unselect the menu title.
  221.       ENDIF
  222.     ENDIF
  223.     '
  224.   CASE 20     ! If it's a redraw message...
  225.     IF window_selected&=handle&  ! and it's our window...
  226.       ~WIND_UPDATE(1)  ! Freeze all AES operations for a screen redraw.
  227.       ~WIND_GET(handle&,11,rx&,ry&,rw&,rh&)  ! Get the first rectangle to
  228.       '                                             be redrawn.
  229.       ~WIND_GET(handle&,4,ax&,ay&,aw&,ah&)  ! Get the size of the window
  230.       '                                           work area.
  231.       REPEAT  ! Start redrawing each rectangle...
  232.         ' If our work area contains the rectangle...
  233.         IF RC_INTERSECT(ax&,ay&,aw&,ah&,rx&,ry&,rw&,rh&)
  234.           CLIP rx&,ry&,rw&,rh& OFFSET ax&,ay&  ! Clip the area to draw.
  235.           ~OBJC_DRAW(maindial_adr%,0,1,rx&,ry&,rw&,rh&)  ! Draw menu.
  236.           CLIP 0,0,WORK_OUT(0),WORK_OUT(1)  ! Clip whole screen.
  237.         ENDIF
  238.         '
  239.         ~WIND_GET(handle&,12,rx&,ry&,rw&,rh&)  ! Get next rectangle to draw.
  240.       UNTIL rw&=0 AND rh&=0  ! All rectangles are drawn.
  241.       ~WIND_UPDATE(0)  ! Resume AES operations.  Redraw is done.
  242.     ENDIF
  243.     '
  244.   CASE 21  ! If it's a window top message...
  245.     IF window_selected&=handle&  ! and if it's our window...
  246.       ~WIND_SET(handle&,10,dummy%,dummy%,dummy%,dummy%)  ! Top our window.
  247.     ENDIF
  248.     '
  249.   CASE 22  ! If it's a window close message...
  250.     IF window_selected&=handle&  ! and if it's our window...
  251.       ~WIND_CLOSE(handle&)  ! Close our window,
  252.       ~WIND_DELETE(handle&)  ! and delete it so AES can use it for something
  253.       '                           else.
  254.       exit!=TRUE  ! Also set our exit flag to true.
  255.     ENDIF
  256.     '
  257.   CASE 28  ! If it's a window move message...
  258.     IF window_selected&=handle&  ! and if it's our window...
  259.       ~WIND_SET(handle&,5,x&,y&,w&,h&)  ! Move our window.
  260.       windx&=x&  ! Save it's x and y coordinates so that if closed
  261.       windy&=y&  ! and then reopened, it will be in the same place.
  262.       ~WIND_GET(handle&,4,wx&,wy&,ww&,wh&)  ! Where's our work area...
  263.       OB_X(maindial_adr%,0)=wx&  ! Set our resource menu coordinates
  264.       OB_Y(maindial_adr%,0)=wy&  ! to the place as our work area,
  265.     ENDIF
  266.     '
  267.   CASE 40  ! If it's an ACC open message...
  268.     IF acc_id&=me_id&  ! and it's our ACC...
  269.       IF resource!  ! and our resource was found...
  270.         IF exit!  ! and we are exited...
  271.           exit!=FALSE  ! Set our exit flag to false because we're now open.
  272.           ~GRAF_MOUSE(0,pattern_adr%)  ! Change our mouse to an arrow.
  273.           @do_window  ! Open our ACC window.
  274.         ELSE  ! If we're already open...
  275.           ~WIND_SET(handle&,10,dummy%,dummy%,dummy%,dummy%)  ! Top our window.
  276.         ENDIF
  277.       ELSE  ! If our resource wasn't found...
  278.         ~FORM_ALERT(1,"[1][Couldn't find resource.|Disabled temporarily.][OK]")
  279.       ENDIF
  280.     ENDIF
  281.     '
  282.   CASE 41  ! If it's an ACC close message...
  283.     ' and we haven't already closed our window, pretend it's closed
  284.     ' because GEM is going to close it for us.  Presumably, the program
  285.     ' that was running when we were opened has finished.
  286.     '
  287.     exit!=TRUE
  288.     '
  289.   ENDSELECT
  290. RETURN
  291. '
  292. '
  293. PROCEDURE process_maindial  ! find and process the button message.
  294.   '
  295.   ' Find out what button the mouse was over when the
  296.   ' left button was pressed.
  297.   object%=OBJC_FIND(maindial_adr%,0,1,mcur_x%,mcur_y%)
  298.   '
  299.   SELECT object%
  300.   CASE infobutn&  ! If the info. button is selected...
  301.     @do_credits  ! display program credits, etc.
  302.   ENDSELECT
  303. RETURN
  304. '
  305. '
  306. PROCEDURE do_credits
  307.   OB_STATE(maindial_adr%,infobutn&)=33
  308.   ~OBJC_DRAW(maindial_adr%,infobutn&,0,windx&,windy&,windw&,windh&)
  309.   ~EVNT_BUTTON(1,1,0)
  310.   OB_STATE(maindial_adr%,infobutn&)=32
  311.   ~OBJC_DRAW(maindial_adr%,infobutn&,0,windx&,windy&,windw&,windh&)
  312.   ~FORM_DIAL(0,0,0,0,0,crdtx&,crdty&,crdtw&,crdth&)
  313.   ~OBJC_DRAW(crdtdial_adr%,0,1,crdtx&,crdty&,crdtw&,crdth&)
  314.   ~FORM_DO(crdtdial_adr%,0)
  315.   OB_STATE(crdtdial_adr%,crdtbutn&)=0
  316.   ~OBJC_DRAW(crdtdial_adr%,crdtbutn&,0,crdtx&,crdty&,crdtw&,crdth&)
  317.   ~FORM_DIAL(3,0,0,0,0,crdtx&,crdty&,crdtw&,crdth&)
  318. RETURN
  319. '
  320. '
  321. '  ** The End **
  322.